import com.itheima.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserApp {
    public static void main(String[] args) {
       /* System.out.println("-------------------------------id---------------------");
        // 加载配置文件
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 获取资源
        // UserService userService = (UserService) ctx.getBean("userService");
        // 根据id获取资源
        UserService userService = ctx.getBean("userService",UserService.class);
        userService.save();

        System.out.println("----------------------------别名----------------------");
        // 根据别名获取资源
        UserService userService1 = ctx.getBean("userService1",UserService.class);
        // userService1.save();
        UserService userService2 = ctx.getBean("userService1",UserService.class);
        // userService2.save();

        *//*
            scope属性
         *//*
        // singleton
        System.out.println(userService);    //  com.itheima.service.impl.UserServiceImpl@5c3bd550
        System.out.println(userService1);   //  com.itheima.service.impl.UserServiceImpl@5c3bd550
        System.out.println(userService2);   //  com.itheima.service.impl.UserServiceImpl@5c3bd550
        // prototype
        UserService userService3 = ctx.getBean("userService3",UserService.class);
        UserService userService4 = ctx.getBean("userService3",UserService.class);
        UserService userService5 = ctx.getBean("userService3",UserService.class);
        // 构造方法执行三次
        System.out.println(userService3);  // com.itheima.service.impl.UserServiceImpl@91161c7
        System.out.println(userService4);  // com.itheima.service.impl.UserServiceImpl@604ed9f0
        System.out.println(userService5);  // com.itheima.service.impl.UserServiceImpl@6a4f787b

        System.out.println("---------------------------生命周期---------------------");
        System.out.println("----------------------singleton");*/
        // 生命周期
        ClassPathXmlApplicationContext ctx2 = new ClassPathXmlApplicationContext("applicationContext.xml");
        // UserService userService6 = ctx2.getBean("userService4", UserService.class);
        // userService6.save();
        // ctx2.close();


        System.out.println("----------------------prototype");
        UserService userService7 = ctx2.getBean("userService5", UserService.class);
        userService7.save();
        ctx2.close();


    }
}
